let _ = require('./tools/lodash.js');
let moment=require('moment');
let transactions=require("./testData").timeData;

// transactions=transactions.map(item=>{
//     item.moment=Moment(+item.timestamp);
//     return item
// })

// let transactionsGroupedByDate=_.groupBy(transactions,item=>item.moment.format('YYYY-MM-DD'));
// let transactionsGroupedByWeek=_.groupBy(transactions,item=>item.moment.format('YYYY-WW'));
// console.log(transactionsGroupedByWeek)

function createTimeSeries(timeSeriesArray) {
    let timeSeriesObj ={
        array: timeSeriesArray.map(item=>{item.moment=moment(+item.timestamp);return item}),
        groupByFormat:function(formatPattern){
            return _.groupBy(timeSeriesObj.array,item=>item.moment.format(formatPattern))
        },
        groupByDate:function(){
            return timeSeriesObj.groupByFormat("YYYY-MM-DD");
        },
        groupByWeek:function(){
            return timeSeriesObj.groupByFormat("YYYY-WW");
        },
        groupByMonth:function(){
            return timeSeriesObj.groupByFormat("YYYY-MM");
        },
        groupByYear:function(){
            return timeSeriesObj.groupByFormat("YYYY");
        }
    }
    return timeSeriesObj;
}

let timeSeries=createTimeSeries(transactions);
console.log(timeSeries.groupByYear())
